import Vue from 'vue'
import Vuex from 'vuex'

Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    //支出标签
    //   list:[{
    //     label:'零食',
    //     value:'snacks'
    // },{
    //     label:'餐饮',
    //     value:'catering'
    // },{
    //     label:'出行',
    //     value:'travel'
    // },{
    //   label:'购物',
    //   value:'shopping'
    // },{
    //   label:'日常',
    //   value:'everyday'
    // },{
    //   label:'房租',
    //   value:'rent'
    // },{
    //   label:'医疗',
    //   value:'medical'
    // },],
    list: [],
    expendPitch: {},//当前支出目标
    incomePitch: {},//当前收入目标
    //收入标签
    // list2:[{
    //   label:'工资',
    //   value:'salary'
    // },{
    //   label:'奖金',
    //   value:'bonus'
    // },{
    //   label:'兼职',
    //   value:'part_time'
    // },{
    //   label:'副业',
    //   value:'avocation'
    // }],
    list2: [],
  },
  mutations: {
    //修改支出目标
    changeExpendPitch(state, value) {
      state.expendPitch = value
    },
    //修改收入目标
    changeIncomePitch(state, value) {
      state.incomePitch = value
    },
    //追加新支出标签
    addExpendList(state, label) {
      state.list.push(label)
    },
    //追加新收入标签
    addIncomeList(state, label) {
      state.list2.push(label)
    },
    //删除支出标签
    deleteExpendList(state, label) {
      let lists = state.list
      for (let i = 0; i < lists.length; i++) {
        if (lists[i].label == label) {
          state.list.splice(i, 1)
          break
        }
      }
      //在localStorage中也删除
      let exp = JSON.parse(window.localStorage.getItem('expendL'))
      for (let i = 0; i < exp.length; i++) {
        if (exp[i].label == label) {
          exp.splice(i, 1)
          break
        }
      }
      window.localStorage.setItem('expendL',JSON.stringify(exp))
    },
    //删除收入标签
    deleteIncomeList(state, label) {
      let lists = state.list2
      for (let i = 0; i < lists.length; i++) {
        if (lists[i].label == label) {
          state.list2.splice(i, 1)
          break
        }
      }
      let inc = JSON.parse(window.localStorage.getItem('incomeL'))
      for (let i = 0; i < inc.length; i++) {
        if (inc[i].label == label) {
          inc.splice(i, 1)
          break
        }
      }
      window.localStorage.setItem('incomeL',JSON.stringify(inc))
    },
  },
  actions: {
  },
  modules: {
  }
})
